//--------------------Sonic CD HUD Script---------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
// Not all of these are used here in the HUD script, some are just used as a way for other objects to globally transmit values


// Game Mode Aliases
private alias 2 : MODE_TIMEATTACK

// Priority
private alias 1 : PRIORITY_ACTIVE

public value UseFlashlight = 0;
public value MouseEnabled = 0;
public value FlashBattery = 5000;

//save ram key
//normal mode beat
// 	saveRAM[6901] = 1
//easy
// 	saveRAM[6900] = 1
//hard
// 	saveRAM[6902] = 1
//extreme
// 	saveRAM[6903] = 1


//Mode Beaten Status
public alias saveRAM[6900] : EasyMode.Beaten
public alias saveRAM[6901] : NormMode.Beaten
public alias saveRAM[6902] : HardMode.Beaten
public alias saveRAM[6903] : XtrmMode.Beaten
//Options
public alias saveRAM[6904] : saved.Sensitivity
public alias saveRAM[6905] : saved.SlenderOST
//mobile
public alias saveRAM[295]: saved.mobile
public alias saveRAM[296]: saved.transmobile




private alias Object.Value0 : Object.Timer 
private alias Object.Value1 : Logo.Xpos
private alias Object.Value2 : Object.MenuChoose
private alias Object.Value3 : Object.ZPos
private alias Object.Value4 : Object.PlayerSelection

private alias object.value6 : object.extraoffset
private alias object.value7 : object.extratarget
private alias object.value8 : object.OriginY
private alias object.value9 : object.casteorAlpha
private alias object.value10 : object.casteorY
private alias object.value11 : object.mapY
private alias object.value12 : object.charY
private alias object.value13 : object.raredog
private alias Object.Value14 : Object.OptionsChoose
private alias Object.Value15 : Object.ExtraChoose
private alias Object.Value16 : Object.TouchTimer



private alias 5 : ST.xspeed

private alias 0 : STARTGAME
private alias 1 : OPTIONSMODE	//mode
private alias 2 : EXTRASMODE
private alias 3 : RETURNTOMENU


private alias 0 : SENSE_HIGHLIGHTED
private alias 1 : OST_HIGHTLIGHTED


private alias 0 : MENU_STARTUP
private alias 1 : MENU_LOWFADEIN
private alias 2 : MENU_LOGOMOVEIN
private alias 3 : MENU_MAINCARD
private alias 4 : MENU_GOTOCHARSEL
private alias 5 : MENU_CHARASEL
private alias 6 : MENU_LOWFADEOUTCHARASEL
private alias 7 : MENU_FADEINTOCHARSEL	//wow what good ordering
private alias 8 : MENU_FADEINTOMAINCARD
private alias 9 : MENU_STARTGAME
private alias 10 : MENU_STARTENDLESS

private alias 11 : MENU_FADEINOPTIONS
private alias 12 : MENU_OPTIONS
private alias 13 : MENU_LEAVEOPTIONS

private alias 14 : MENU_FADEINEXTRAS
private alias 15 : MENU_EXTRAS
private alias 16 : MENU_LEAVEEXTRAS

reserve function SlenderMenu_Android

function SlenderMenu_Android
	CheckTouchRect(0, 0, screen.xsize, screen.ysize)
	if checkResult == -1
		Object.TouchTimer = false
	end if
	if Object.TouchTimer == 0
		switch object.state 
			case MENU_MAINCARD
				temp0 = screen.xcenter
				temp1 = 0
				temp1 += screen.xsize
				CheckTouchRect(temp0, 100, temp1, 119)
				if CheckResult > -1
					Object.TouchTimer = 1
					Object.MenuChoose = 0
					inputpress.buttonA = 1
				end if

				temp0 = screen.xcenter
				temp1 = 0
				temp1 += screen.xsize
				CheckTouchRect(temp0, 122, temp1, 143)
				if CheckResult > -1
					Object.TouchTimer = 1
					Object.MenuChoose = 1
					inputpress.buttonA = 1
				end if	

				temp0 = screen.xcenter
				temp1 = 0
				temp1 += screen.xsize
				CheckTouchRect(temp0, 146, temp1, 165)
				if CheckResult > -1
					Object.TouchTimer = 1
					Object.MenuChoose = 2
					inputpress.buttonA = 1
				end if	

				temp0 = screen.xcenter
				temp1 = 0
				temp1 += screen.xsize
				CheckTouchRect(temp0, 168, temp1, 188)
				if CheckResult > -1
					Object.TouchTimer = 1
					Object.MenuChoose = 3
					inputpress.buttonA = 1
				end if	
			break
			case MENU_OPTIONS
				temp0 = 0
				temp1 = 80
				CheckTouchRect(temp0, 0, temp1, 82)
				if CheckResult > -1
					inputPress.buttonB = 1
				end if

				temp0 = object.value17
				temp0 += screen.xcenter
				temp0 += 45
				temp1 = object.value17
				temp1 += screen.xcenter
				temp1 += 60
				CheckTouchRect(temp0, 85, temp1, 100)
				if CheckResult > -1
					Object.TouchTimer = 1
					Object.OptionsChoose = 0
					inputpress.left = 1
				end if	

				CheckTouchRect(temp0, 115, temp1, 135)
				if CheckResult > -1
					Object.TouchTimer = 1
					Object.OptionsChoose = 1
					inputpress.left = 1
				end if	


				temp0 = object.value17
				temp0 += screen.xcenter
				temp0 += 85
				temp1 = object.value17
				temp1 += screen.xcenter
				temp1 += 100
				CheckTouchRect(temp0, 85, temp1, 100)
				if CheckResult > -1
					Object.TouchTimer = 1
					Object.OptionsChoose = 0
					inputpress.left = 1
				end if	

				CheckTouchRect(temp0, 115, temp1, 135)
				if CheckResult > -1
					Object.TouchTimer = 1
					Object.OptionsChoose = 1
					inputpress.left = 1
				end if					


			break
			case MENU_EXTRAS
				temp0 = 0
				temp1 = 80
				CheckTouchRect(temp0, 0, temp1, 82)
				if CheckResult > -1
					inputPress.buttonB = 1
				end if

				CheckEqual(EasyMode.Beaten, 1)
				temp0 = checkResult
				CheckEqual(NormMode.Beaten, 1)
				temp0 |= checkResult
				CheckEqual(HardMode.Beaten, 1)
				temp0 |= checkResult
				CheckEqual(XtrmMode.Beaten, 1)
				temp0 |= checkResult
				if temp0 == 1 	//beat at least one mode


					temp0 = object.value17
					temp0 += screen.xcenter
					temp0 -= 80
					temp1 = object.value17
					temp1 += screen.xcenter
					temp1 += 80
					CheckTouchRect(temp0, 64, temp1, 111)
					if CheckResult > -1
						Object.TouchTimer = 1
						Object.ExtraChoose = 0
						inputpress.start = 1
					end if	

					CheckTouchRect(temp0, 115, temp1, 166)
					if CheckResult > -1
						Object.TouchTimer = 1
						Object.ExtraChoose = 1
						inputpress.start = 1
					end if	


					if saveram[6001] == 1
						CheckTouchRect(temp0, 168, temp1, 220)
						if CheckResult > -1
							Object.TouchTimer = 1
							Object.ExtraChoose = 2
							inputpress.start = 1
						end if	

					end if
				else
				
				end if
			break
			case MENU_CHARASEL
				temp0 = 0
				temp1 = 80
				CheckTouchRect(temp0, 0, temp1, 82)
				if CheckResult > -1
					inputPress.buttonB = 1
				end if

				temp0 = screen.xsize
				temp0 -= 75
				CheckTouchRect(temp0, 0, screen.xsize, 82)
				if CheckResult > -1
					inputPress.start = 1
				end if

				temp0 = object.value17
				temp0 += screen.xcenter
				temp0 -= 120
				temp1 = object.value17
				temp1 += screen.xcenter
				temp1 -= 80
				CheckTouchRect(temp0, 64, temp1, 200)
				if CheckResult > -1
					Object.TouchTimer = 1
					inputpress.left = 1
				end if	

				temp0 += 190
				temp1 += 190
				CheckTouchRect(temp0, 64, temp1, 200)
				if CheckResult > -1
					Object.TouchTimer = 1
					inputpress.right = 1
				end if	


			break
		end switch
	end if
end function

event ObjectMain
	Callfunction(SlenderMenu_Android)

	switch object.state
	case MENU_STARTUP	//setup
		object.timer = 255
		rand(object.raredog, 100)
		Logo.Xpos = screen.xcenter			
		if ReturnToSlenderMenu == 0
			PlaySfx(SfxName[SlenderThunder], 0)
			StopMusic()
			Object.YPos += 0x2500000
			object.state++
			object.casteorAlpha = 255
			SetClassicFade(color7, color7, color7, 256)			
		else
			SetClassicFade(0, 0, 0, Object.Timer)
			object.state++
		end if	

	//	PlayMusic(0)	
		break
	case MENU_LOWFADEIN	//fade in
		if object.timer > -340
			object.timer -= 10
		else
			object.timer = -340	
		end if

		// skip all
		if ReturnToSlenderMenu == 0
			if inputPress.start == true
				object.YPos = object.OriginY
				object.timer = -340
				object.casteorAlpha = 0
			end if	
			SetClassicFade(color7, color7, color7, Object.Timer)
		else
			SetClassicFade(0, 0, 0, Object.Timer)
		end if	
		if object.timer == -340
			if ReturnToSlenderMenu == 0
				// start pan
				if object.YPos > object.OriginY
					Object.YPos -= 0x30000
					object.casteorY--	
				end if		
				if object.casteorAlpha > 0
					object.casteorAlpha -= 6
				else
					object.casteorAlpha = 0				
				end if			
			else
				object.YPos = object.OriginY
				object.timer = -340
				object.casteorAlpha = 0
			end if	
			if object.YPos <= object.OriginY
				music.volume = 100
				PlayMusic(0)	
				object.timer = 0
				ReturnToSlenderMenu = 0
				object.state++
			end if
		end if
		break
	case MENU_LOGOMOVEIN	//logo move in
		object.timer++
		object.alpha += 8
		if object.timer == 50
			object.timer = 0
			Object.MenuChoose = 0
			object.state++
		end if	
		break
	case MENU_MAINCARD
	//Controls
		if inputpress.down == 1
			if Object.MenuChoose > 2
				Object.MenuChoose = 0
			else	
				Object.MenuChoose++
			end if
			PlaySfx(SfxName[Score Add], 0)			
		end if

		if inputpress.up == 1
			if Object.MenuChoose < 1
				Object.MenuChoose = 3
			else	
				Object.MenuChoose--
			end if
			PlaySfx(SfxName[Score Add], 0)			
		end if


		if inputpress.buttonA == 1
			inputPress.start = 1
		end if


		if inputPress.start == 1
			PlaySfx(SfxName[Lamp Post], 0)
			switch Object.MenuChoose
			case 0	//lol
			case 1
			case 2
				object.timer = 0
				object.state = MENU_GOTOCHARSEL
				object.alpha = 255
				break		
			case 3	//lol
				object.state = 99
				break
			default

			break
			end switch
		end if	

		if inputpress.buttonB == 1
			object.state = 99
		end if
		break
	case MENU_GOTOCHARSEL	//transition to next thing
		object.alpha -= 20
		if object.alpha <= 0
			object.alpha = 0
			object.charY = 0
			switch object.MenuChoose
			case 0
				object.state = MENU_FADEINTOCHARSEL
			break
			case 1
				object.state = MENU_FADEINOPTIONS
			break
			case 2
				object.state = MENU_FADEINEXTRAS
			break
			end switch
		end if
		break
	case MENU_CHARASEL
		if inputpress.buttonA == 1
			inputPress.start = 1
		end if

		if object.alpha <= 255
			object.alpha += 8			
		end if

		if inputpress.right == 1
			if Object.PlayerSelection > 2
				Object.PlayerSelection = 0
			else	
				Object.PlayerSelection++
			end if
			PlaySfx(SfxName[Score Add], 0)			
		end if

		if inputpress.left == 1
			if Object.PlayerSelection < 1
				Object.PlayerSelection = 3
			else	
				Object.PlayerSelection--
			end if
			PlaySfx(SfxName[Score Add], 0)			
		end if

		if inputpress.start == 1
			StopMusic()
			PlaySfx(SfxName[SlenderThunder], 0)
			PlaySfx(SfxName[Lamp Post], 0)
			options.gamemode = 0
			object.timer = 0
			object.state = MENU_STARTGAME
		end if

		if inputPress.buttonB == 1
			PlaySfx(SfxName[Skidding], 0)
			object.state = 6	//exiting what fun
		end if			
		break
	case MENU_LOWFADEOUTCHARASEL
		object.alpha -= 16
		if object.alpha <= 0
			object.alpha = 0
			object.state = 8
		end if
		break
	case MENU_FADEINTOCHARSEL
		if object.alpha < 255
			object.alpha += 8		
		end if
		if object.extraoffset >= object.extratarget
			object.timer = 0
			object.state = MENU_CHARASEL	
		end if	
		break
	case MENU_FADEINTOMAINCARD
		object.alpha += 8
		if object.alpha >= 255
			object.state = MENU_MAINCARD
		end if
		break

	case MENU_STARTGAME
		object.timer += 4
		object.alpha -= 8

		options.gamemode = 0
		object.scale += 64
		if object.timer >= 500
			switch Object.PlayerSelection
			case 0
				stage.playerlistpos = 1
			break
			case 1
				stage.playerlistpos = 0
			break
			case 2
				stage.playerlistpos = 2
			break
			case 3
				stage.playerlistpos = 5
			break
			end switch
			stage.activeList = BONUS_STAGE
			stage.listPos = 11
			LoadStage()
		end if

		break

	case MENU_STARTENDLESS
		music.volume -= 8
		object.timer += 8
		SetClassicFade(0, 0, 0, Object.Timer)
		if object.timer >= 255
			music.volume = 0
			StopMusic()
			switch Object.ExtraChoose
				case 0
					options.gamemode = 1			
					stage.playerlistpos = 0
					stage.activeList = BONUS_STAGE
					stage.listPos = 11
				break
				case 1
					stage.playerlistpos = 0
					stage.activeList = BONUS_STAGE
					stage.listPos = 15
				break	
				case 2
					stage.playerlistpos = 0
					stage.activeList = BONUS_STAGE
					stage.listPos = 14
				break				
			end switch
			LoadStage()				
		end if
		break
	case MENU_FADEINOPTIONS
		if object.alpha <= 255
			object.alpha += 8	
		else
			object.alpha = 255
			object.state++
		end if
	break
	case MENU_OPTIONS

		if inputpress.down == 1
			Object.OptionsChoose = 1
			PlaySfx(SfxName[Score Add], 0)			
		end if

		if inputpress.up == 1
			Object.OptionsChoose = 0
			PlaySfx(SfxName[Score Add], 0)			
		end if

		if Object.OptionsChoose == 0	//sens
			if inputpress.right == 1
				if saved.Sensitivity < 10
					saved.Sensitivity++
				else
					saved.Sensitivity = 10
				end if
				PlaySfx(SfxName[Score Add], 0)		
			end if

			if inputpress.left == 1
				if saved.Sensitivity > 2
					saved.Sensitivity--
				else
					saved.Sensitivity = 2
				end if			
				PlaySfx(SfxName[Score Add], 0)		
			end if
		else	//music	
			if inputpress.right == 1
				saved.SlenderOST = 1 //matt
				PlaySfx(SfxName[Score Add], 0)		
			end if

			if inputpress.left == 1
				PlaySfx(SfxName[Score Add], 0)		
				saved.SlenderOST = 0 // me
			end if
			
		end if
	
		if inputpress.buttonB == 1
			WriteSaveRAM()
			object.state = MENU_LEAVEOPTIONS
		end if
	break
	case MENU_LEAVEOPTIONS
		if object.alpha >= 0
			object.alpha -= 16
		else
			object.alpha = 0
			object.state = 8
		end if
	break
	case MENU_FADEINEXTRAS
		if object.alpha <= 255
			object.alpha += 8	
		else
			object.alpha = 255
			object.state++
		end if
	break
	case MENU_EXTRAS
		if inputpress.down == 1
			if Object.ExtraChoose > 1
				Object.ExtraChoose = 0
			else	
				Object.ExtraChoose++
			end if
			PlaySfx(SfxName[Score Add], 0)			
		end if

		if inputpress.up == 1
			if Object.ExtraChoose < 1
				Object.ExtraChoose = 2
			else	
				Object.ExtraChoose--
			end if
			PlaySfx(SfxName[Score Add], 0)			
		end if

		if inputpress.start == 1
			CheckEqual(EasyMode.Beaten, 1)
			temp0 = checkResult
			CheckEqual(NormMode.Beaten, 1)
			temp0 |= checkResult
			CheckEqual(HardMode.Beaten, 1)
			temp0 |= checkResult
			CheckEqual(XtrmMode.Beaten, 1)
			temp0 |= checkResult
			if temp0 == 1 	//beat at least one mode
				PlaySfx(SfxName[Lamp Post], 0)
				switch Object.ExtraChoose
					case 2
						if saveRAM[6001] == 0	
							PlaySfx(SfxName[Bonus Points], 0)	
						else	
							object.state = MENU_STARTENDLESS
						end if
					break
					default
						object.state = MENU_STARTENDLESS
					break
				end switch
			else
				PlaySfx(SfxName[Bonus Points], 0)	
			end if
		end if


		if inputPress.buttonb == 1
			object.state = MENU_LEAVEEXTRAS
		end if
	break
	case MENU_LEAVEEXTRAS
		if object.alpha >= 0
			object.alpha -= 16
		else
			object.alpha = 0
			object.state = 8
		end if
	break	
	case 99	//exit
		music.volume -= 8
		object.timer += 8
		SetClassicFade(0, 0, 0, Object.Timer)
		if object.timer >= 255
			music.volume = 0
			StopMusic()
			stage.activeList = PRESENTATION_STAGE
			stage.listPos = 6
			LoadStage()				
		end if
		break

	end switch

	

	//Techinal Stuff

	TileLayer[0].Angle = 128


	// X/Z movement
	Sin(TileLayer[0].XPos, TileLayer[0].Angle)
	Cos(TileLayer[0].ZPos, TileLayer[0].Angle)
	TileLayer[0].XPos *= 0x12800
	TileLayer[0].ZPos *= 0x12800
	TileLayer[0].XPos += object.xpos
	TileLayer[0].ZPos += object.zpos

	// Just take Sonic's Y Position, smooth it out a bit, and offset it by 88 pixels
	TileLayer[0].YPos = object.YPos
	TileLayer[0].YPos += 0x1280000	

end event


event ObjectDraw
	//Not Dead
	DrawRect(0, 0, screen.xsize, screen.ysize, 0, 0, 0, 128)

	//SLIDING STUFF
	temp0 = object.extratarget
	temp0 -= object.extraoffset
	Abs(temp0)

	temp1 = object.extratarget
	temp1 -= object.extraoffset

	//Make sure it's exactly in the spot
	if temp0 < 6
		if object.extraoffset > object.extratarget
			object.extraoffset--
		else
			if object.extraoffset < object.extratarget
				object.extraoffset++
			else
				object.extraoffset = object.extratarget
			end if
		end if
	else
		temp1 >>= 2
		object.extraoffset += temp1
	end if	
	object.InkEffect = INK_ALPHA

	// casteor logo
	temp0 = object.alpha
	object.alpha = object.casteorAlpha
	temp1 = screen.ycenter
	temp1 += object.casteorY
	if object.raredog == 1
		DrawSpriteScreenFX(34, FX_INK, screen.xcenter, temp1)	
	end if
	object.alpha = temp0

	switch object.state
		case MENU_LOGOMOVEIN
			object.extratarget = screen.xsize
			if screen.xsize < 426
				object.extratarget -= 40
			else
				object.extratarget += 28
			end if

			temp3 = screen.xsize
			temp3 += screen.xcenter
			temp3 -= object.extraoffset			
			if screen.xsize < 426
				temp3 /= 2
				if screen.xsize == 384	//16:9
					temp3 += 25
				end if				
			end if

			temp4 = 0
			temp4 -= screen.xcenter
			temp4 += object.extraoffset			
			if screen.xsize < 426
				temp4 += 120
				temp4 /= 2
			end if


			//LOGO
			DrawSpriteScreenFX(0, FX_INK, temp3, screen.ycenter)	
			//BUTTONS
			DrawSpriteScreenFX(1, FX_INK, temp3, screen.ycenter)	
			if screen.xsize < 426
				temp4 += 12
				if screen.xsize == 384	//16:9
					temp4 += 25
				end if				
			else
				temp4 -= 68
			end if
			DrawSpriteScreenFX(6, FX_INK, temp4, screen.ycenter)
			break
		case MENU_MAINCARD
		case MENU_FADEINTOMAINCARD
		case 99	//exit

			temp3 = screen.xsize
			temp3 -= screen.xsize
			temp3 += screen.xcenter
			if screen.xsize < 426
				temp3 += 40
			else
				temp3 -= 28
			end if

			if screen.xsize < 426
				temp3 /= 2
				if screen.xsize == 384	//16:9
					temp3 += 25
				end if
			end if

			//dont move
			object.extratarget = 0
			//LOGO
			DrawSpriteScreenFX(0, FX_INK, temp3, screen.ycenter)	
			//BUTTONS
			DrawSpriteScreenFX(1, FX_INK, temp3, screen.ycenter)	


				switch Object.MenuChoose
					case STARTGAME
						DrawSpriteScreenFX(2, FX_INK, temp3, screen.ycenter)	
						temp4 = screen.ycenter
						temp4 -= 16
						break
					case OPTIONSMODE
						DrawSpriteScreenFX(3, FX_INK, temp3, screen.ycenter)	
						temp4 = screen.ycenter
						temp4 += 7
						break		
					case EXTRASMODE
						DrawSpriteScreenFX(4, FX_INK, temp3, screen.ycenter)	
						temp4 = screen.ycenter
						temp4 += 30
						break			
					case RETURNTOMENU
						DrawSpriteScreenFX(40, FX_INK, temp3, screen.ycenter)	
						temp4 = screen.ycenter
						temp4 += 53
						break						
				end switch
				temp3 -= 20

				//Scrolling
				temp5 = temp4
				temp5 -= screen.ycenter
				temp1 = temp5
				temp1 -= object.mapY
				temp2 = temp1
				Abs(temp2)

				//Make sure it's exactly in the spot
				if temp2 < 6
					if object.mapY > temp5
						object.mapY--
					else
						if object.mapY < temp5
							object.mapY++
						else
							object.mapY = temp5
						end if
					end if
				else
					temp1 >>= 2
					object.mapY += temp1
				end if

				temp4 = object.mapY
				temp4 += screen.ycenter
				DrawSpriteScreenFX(5, FX_INK, temp3, temp4)		

				if screen.xsize < 426
					temp3 += 52
				else
					temp3 += 8
				end if

				
				DrawSpriteScreenFX(6, FX_INK, temp3, screen.ycenter)		
			

				// switch stage.playerlistpos
				// case 0	//normal mode beat
				// 	saveRAM[6901] = 1
				// break
				// case 1	//easy
				// 	saveRAM[6900] = 1
				// break
				// case 2	//hard
				// 	saveRAM[6902] = 1
				// break
				// case 5	//extreme
				// 	saveRAM[6903] = 1
				// break
				// end switch

				
				if screen.xsize < 426
					temp3 += 280
				else
					temp3 += 325
				end if
				if saveRAM[6900] == 1
					temp4 = screen.ycenter
					temp4 += 100
					DrawSpriteScreenFX(36, FX_INK, temp3, temp4)		
				end if


				if saveRAM[6901] == 1
					temp3 += 20
					temp4 = screen.ycenter
					temp4 += 100
					DrawSpriteScreenFX(37, FX_INK, temp3, temp4)		
				end if

				if saveRAM[6902] == 1
					temp3 += 20
					temp4 = screen.ycenter
					temp4 += 100
					DrawSpriteScreenFX(38, FX_INK, temp3, temp4)		
				end if

				if saveRAM[6903] == 1
					temp3 += 20
					temp4 = screen.ycenter
					temp4 += 100
					DrawSpriteScreenFX(39, FX_INK, temp3, temp4)		
				end if				
				
				break
		case MENU_GOTOCHARSEL

			temp3 = screen.xsize
			temp3 -= screen.xcenter
			if screen.xsize < 426
				temp3 += 40
				temp3 /= 2
				if screen.xsize == 384	//16:9
					temp3 += 25
				end if	
			else
				temp3 -= 28	
			end if			

			object.extratarget = 0
			//LOGO
			DrawSpriteScreenFX(0, FX_INK, temp3, screen.ycenter)	
			//BUTTONS
			DrawSpriteScreenFX(1, FX_INK, temp3, screen.ycenter)	
			//render

			if screen.xsize < 426
				temp3 += 32
			else
				temp3 -= 12
			end if
			
			DrawSpriteScreenFX(6, FX_INK, temp3, screen.ycenter)	
			break		
		case MENU_FADEINTOCHARSEL
			DrawSpriteScreenFX(7, FX_INK, screen.xcenter, screen.ycenter)	

			object.extratarget = screen.xsize
			object.extratarget += 20

			temp3 = screen.xsize
			temp3 += screen.xcenter
			temp3 += 20
			temp3 -= object.extraoffset

			switch Object.PlayerSelection
			case 0	//Sonic!
				DrawSpriteScreenFX(9, FX_INK, temp3, screen.ycenter)	
				break
			case 1	//Tails!
				DrawSpriteScreenFX(8, FX_INK, temp3, screen.ycenter)	
				break			
			case 2	//Knuckles!
				DrawSpriteScreenFX(10, FX_INK, temp3, screen.ycenter)	
				break			
			case 3	//Amy!
				DrawSpriteScreenFX(11, FX_INK, temp3, screen.ycenter)	
				break			
			end switch	
			break
		case MENU_CHARASEL
		case MENU_LOWFADEOUTCHARASEL
			object.extratarget = 0

			if saved.mobile == 1
				DrawSpriteScreenFX(65, FX_INK, 8, 12)
				temp0 = screen.xsize
				temp0 -= 64
				DrawSpriteScreenFX(66, FX_INK, temp0, 12)
			end if


			DrawSpriteScreenFX(7, FX_INK, screen.xcenter, screen.ycenter)	

			temp3 = screen.xsize
			temp3 -= screen.xcenter

			object.charY++
			temp4 = 0
			Sin256(temp4, object.charY)
			temp4 /= 50
			temp4 += screen.ycenter

			switch Object.PlayerSelection
			case 0	//Tails!
				DrawSpriteScreenFX(14, FX_INK, temp3, screen.ycenter)	
				DrawSpriteScreenFX(9, FX_INK, temp3, temp4)				
				break
			case 1	//Sonic!
				DrawSpriteScreenFX(15, FX_INK, temp3, screen.ycenter)	
				DrawSpriteScreenFX(8, FX_INK, temp3, temp4)	
				break			
			case 2	//Knuckles!
				DrawSpriteScreenFX(16, FX_INK, temp3, screen.ycenter)	
				DrawSpriteScreenFX(10, FX_INK, temp3, temp4)	
				break			
			case 3	//Amy!
				DrawSpriteScreenFX(17, FX_INK, temp3, screen.ycenter)	
				DrawSpriteScreenFX(11, FX_INK, temp3, temp4)	
				break			
			end switch	
		

			DrawSpriteScreenFX(13, FX_INK, temp3, screen.ycenter)	
			temp3 += 200
			DrawSpriteScreenFX(12, FX_INK, temp3, screen.ycenter)	
			temp5 = screen.xcenter
			temp5 -= 43
			DrawSpriteScreenFX(35, FX_INK, temp5, 32)	
			break	
		case MENU_STARTGAME
			object.extratarget = 0
		
			DrawSpriteScreenFX(7, FX_INK, screen.xcenter, screen.ycenter)	

			temp3 = screen.xcenter	

			DrawSpriteScreenFX(13, FX_INK, temp3, screen.ycenter)	
			temp3 += 200
			DrawSpriteScreenFX(12, FX_INK, temp3, screen.ycenter)	

			temp3 -= 200

			temp4 = 0
			Sin256(temp4, object.charY)
			temp4 /= 50
			temp4 += screen.ycenter

			switch Object.PlayerSelection
			case 0	//Sonic!
				DrawSpriteScreenFX(9, FX_SCALE, temp3, temp4)	
				break
			case 1	//Tails!
				DrawSpriteScreenFX(8, FX_SCALE, temp3, temp4)	
				break			
			case 2	//Knuckles!
				DrawSpriteScreenFX(10, FX_SCALE, temp3, temp4)	
				break			
			case 3	//Amy!
				DrawSpriteScreenFX(11, FX_SCALE, temp3, temp4)	
				break			
			end switch	
		

			break		
			case MENU_FADEINOPTIONS
			case MENU_OPTIONS
			case MENU_LEAVEOPTIONS


				if saved.mobile == 1
					DrawSpriteScreenFX(65, FX_INK, 8, 12)
				end if

				object.extratarget = 0

				temp3 = screen.xsize
				temp3 -= screen.xsize
				temp3 += screen.xcenter
				temp3 -= 165
				DrawSpriteScreenFX(3, FX_INK, temp3, 32)	

				temp0 = screen.xcenter 
				temp0 -= 29
				temp1 = screen.ycenter
				temp1 -= 32
				DrawSpriteScreenFX(41, FX_INK, temp0, temp1)	
				temp1  += 32
				DrawSpriteScreenFX(54, FX_INK, temp0, temp1)	

				
				temp0 = screen.xcenter 
				temp0 += 70
				temp1 = screen.ycenter
				temp1 -= 32				
				DrawNumbers(42, temp0, temp1, saved.Sensitivity, 2, 8, 0)

				temp0 = screen.xcenter 
				temp0 += 59
				temp1  += 32
				if saved.SlenderOST == 0
					DrawSpriteScreenFX(57, FX_INK, temp0, temp1)	
				else
					DrawSpriteScreenFX(58, FX_INK, temp0, temp1)	
				end if

			
				//ost
				temp0 = screen.xcenter 
				temp0 += 49				

				temp1 = screen.ycenter
				temp1 -= 32		
				DrawSpriteScreenFX(59, FX_INK, temp0, temp1)	

				temp1 += 32	
				DrawSpriteScreenFX(59, FX_INK, temp0, temp1)						
				


				temp3 = screen.xsize
				temp3 -= screen.xsize
				temp3 += screen.xcenter
				temp3 -= 260
				switch Object.OptionsChoose
					case SENSE_HIGHLIGHTED
						temp4 = screen.ycenter
						temp4 -= 32
						break
					case OST_HIGHTLIGHTED
						temp4 = screen.ycenter
						temp4 -= 1
						break		
				end switch
				
				//page
				//Scrolling
				temp5 = temp4
				temp5 -= screen.ycenter
				temp1 = temp5
				temp1 -= object.mapY
				temp2 = temp1
				Abs(temp2)

				//Make sure it's exactly in the spot
				if temp2 < 6
					if object.mapY > temp5
						object.mapY--
					else
						if object.mapY < temp5
							object.mapY++
						else
							object.mapY = temp5
						end if
					end if
				else
					temp1 >>= 2
					object.mapY += temp1
				end if

				temp4 = object.mapY
				temp4 += screen.ycenter
				DrawSpriteScreenFX(5, FX_INK, temp3, temp4)	

				//saved.Sensitivity
				//DrawNumbers(int startingFrame, int iXPos, int iYPos, int value, int digitCnt, int spacing, bool showAllDigits)
				
			break
			case MENU_FADEINEXTRAS
			case MENU_EXTRAS
			case MENU_LEAVEEXTRAS
				if saved.mobile == 1
					DrawSpriteScreenFX(65, FX_INK, 8, 12)
				end if


				object.extratarget = 0
				temp3 = screen.xsize
				temp3 -= screen.xsize
				temp3 += screen.xcenter
				temp3 -= 170
				DrawSpriteScreenFX(4, FX_INK, temp3, 8)	

				temp3 = screen.xcenter

				// public alias saveRAM[6900] : EasyMode.Beaten
				// public alias saveRAM[6901] : NormMode.Beaten
				// public alias saveRAM[6902] : HardMode.Beaten
				// public alias saveRAM[6903] : XtrmMode.Beaten

				CheckEqual(EasyMode.Beaten, 1)
				temp0 = checkResult
				CheckEqual(NormMode.Beaten, 1)
				temp0 |= checkResult
				CheckEqual(HardMode.Beaten, 1)
				temp0 |= checkResult
				CheckEqual(XtrmMode.Beaten, 1)
				temp0 |= checkResult
				if temp0 == 1 	//beat at least one mode
					DrawSpriteScreenFX(61, FX_INK, temp3, 64)		//endless
					DrawSpriteScreenFX(62, FX_INK, temp3, 117)		//sounds
					if saveRAM[6001] == 1
						DrawSpriteScreenFX(63, FX_INK, temp3, 170)		//play it
					else
						DrawSpriteScreenFX(64, FX_INK, temp3, 170)		//beat fred 
					end if
				else												
					DrawSpriteScreenFX(60, FX_INK, temp3, 64)		//lock
					DrawSpriteScreenFX(60, FX_INK, temp3, 117)		//lock
					DrawSpriteScreenFX(60, FX_INK, temp3, 170)		//lock
				end if


				temp3 = screen.xsize
				temp3 -= screen.xsize
				temp3 += screen.xcenter
				temp3 -= 240
				switch Object.ExtraChoose
					case 0	//end
						temp4 = screen.ycenter
						temp4 -= 38
						break
					case 1//	sound
						temp4 = screen.ycenter
						temp4 += 16
						break		
					case 2//	gurt
						temp4 = screen.ycenter
						temp4 += 68
						break							
				end switch
				
				//page
				//Scrolling
				temp5 = temp4
				temp5 -= screen.ycenter
				temp1 = temp5
				temp1 -= object.mapY
				temp2 = temp1
				Abs(temp2)

				//Make sure it's exactly in the spot
				if temp2 < 6
					if object.mapY > temp5
						object.mapY--
					else
						if object.mapY < temp5
							object.mapY++
						else
							object.mapY = temp5
						end if
					end if
				else
					temp1 >>= 2
					object.mapY += temp1
				end if

				temp4 = object.mapY
				temp4 += screen.ycenter
				DrawSpriteScreenFX(5, FX_INK, temp3, temp4)	
				temp3 += 200
				DrawSpriteScreenFX(5, FX_INK, temp3, temp4)	

			break
		default
			object.extratarget = 0
			break
	end switch
end event


event ObjectStartup
	//since sensitivity is a saveram, and they all start at 0, just do this			also incase you somehow break it
	if saved.Sensitivity == 0
		saved.Sensitivity = 6
	end if	

	LoadSpriteSheet("3D_Test/Objects2.gif")
	
	//logo
	SpriteFrame(32, -96, 184, 57, 327, 1)	//0
	//buttons
	SpriteFrame(128, -16, 67, 80, 130, 431)		//1

	//HIGHLIGHTED
	//Start
	SpriteFrame(156, -16, 39, 11, 472, 59)		//2
	//Options
	SpriteFrame(143, 7, 52, 11, 213, 454)		//3
	//Extras
	SpriteFrame(147, 30, 48, 11, 217, 477)		//4

	//page icon
	SpriteFrame(130, 0, 15, 11, 360, 59)		//5

	//render
	SpriteFrame(-150, -64, 178, 147, 1, 1)		//6

	//choose
	SpriteFrame(-80, -102, 166, 11, 345, 117)		//7

	//char renders
	//Sonic Render
	SpriteFrame(-56, -42, 103, 148, 1, 229)		//8
	//Tails Render
	SpriteFrame(-84, -32, 160, 116, 351, 246)		//9
	//Knux Render
	SpriteFrame(-64, -42, 129, 134, 0, 378)		//10
	//Amy Render
	SpriteFrame(-64, -44, 130, 149, 381, 363)		//11

	//Arrow Left
	SpriteFrame(-120, 0, 32, 32, 396, 153)		//12
	//Arrow Right
	SpriteFrame(-120, 0, 32, 32, 429, 153)		//13


	//Easy
	SpriteFrame(-12, -72, 31, 11, 471, 155)		//14
	//Normal
	SpriteFrame(-22, -72, 47, 11, 463, 171)		//15
	//Hard
	SpriteFrame(-16, -72, 31, 11, 471, 187)		//16
	//Extreme
	SpriteFrame(-26, -72, 57, 11, 454, 201)		//17	
	
	// 18 - battery bar
	SpriteFrame(-194, -22, 18, 32, 344, 153)
	SpriteFrame(-194, -12, 24, 8, 322, 126)//19
	SpriteFrame(-194, -2, 24, 8, 322, 136)	//20
	SpriteFrame(-194,  8, 24, 8, 322, 146)	//21
	SpriteFrame(-194,  18, 24, 8, 322, 156)	//22



	// 23 - SLENDERMAN!!
	SpriteFrame(-30, -24, 63, 112, 339, 1)


	SpriteFrame(-34, -30, 68, 30, 0, 412) //107 Static
	SpriteFrame(-34, -30, 68, 30, 0, 442)//25
	SpriteFrame(-34, -30, 68, 30, 0, 472)//26
	SpriteFrame(-34, -30, 68, 30, 68, 412)//27
	SpriteFrame(-34, -30, 68, 30, 68, 442)//28
	SpriteFrame(-34, -30, 68, 30, 68, 472)//29
	SpriteFrame(-34, -30, 68, 30, 136, 412)//30
	SpriteFrame(-34, -30, 68, 30, 136, 442)//31
	SpriteFrame(-34, -30, 68, 30, 136, 472)//32


	SpriteFrame(-24, -30, 64, 64, 0, 413) //33


	SpriteFrame(-64,-64,128,128,180,1) // 34 casteor

	SpriteFrame(0,0,96,10,365,186) // 35 controls

	// 36 - Trophies
	SpriteFrame(-194, -22, 18, 32, 306, 153)	//easy
	SpriteFrame(-194, -22, 18, 32, 325, 153)	//medium	7
	SpriteFrame(-194, -22, 18, 32, 344, 153)	//hard	8
	SpriteFrame(-194, -22, 18, 32, 357, 84)	//extreme	9

	SpriteFrame(130, 53, 65, 11, 446, 105)		//40	MainMenu Select, yes really

	SpriteFrame(-70, 0, 76, 11, 130, 419)		//41 Sensitivity

	//numbers
	//42-53
	temp5 = 383
	while temp5 < 418
		temp6 = 130
		while temp6 < 165
			SpriteFrame(0, 0, 8, 11, temp6, temp5)
			temp6 += 9
		loop
		temp5 += 12
	loop		

	SpriteFrame(-70, 0, 27, 11, 167, 407)		//54 OST

	SpriteFrame(0, 0, 8, 11, 315, 129)//55 Mini Arrows Right
	SpriteFrame(0, 0, 8, 11, 306, 129)//56 Mini Arrows	Left

	SpriteFrame(0, 0, 31, 11, 195, 407)//57 Cast
	SpriteFrame(0, 0, 32, 11, 207, 419)//58 Matt!

	SpriteFrame(0, 0, 51, 11, 166, 395)//59 mini arrows!
	SpriteFrame(-75, 0, 149, 47, 1, 149)//60 extras box locked
	SpriteFrame(-75, 0, 149, 47, 304, 198)//61 extras box endless
	SpriteFrame(-75, 0, 149, 47, 151, 149)//62 sound test
	SpriteFrame(-75, 0, 149, 47, 105, 197)//63 special battle
	SpriteFrame(-75, 0, 149, 47, 105, 245)//64fred locked

	SpriteFrame(-3, -6, 64, 64, 286, 246) //65	
	SpriteFrame(-3, -6, 64, 64, 286, 311) //65	
	SetMusicTrack("SlenderMenu.ogg", 0, 1)

	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[4].Type = TypeName[Main Menu]
	Object[4].OriginY = Object[4].YPos
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[4].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[4].DrawOrder = 6
	
	// Cycle through all UFO objects in the scene and set them up
	ArrayPos0 = 32
	while ArrayPos0 < 1056
		if Object[ArrayPos0].Type == TypeName[Main Menu]
			
			// Due to the difference between editor and game, turn YPos into ZPos here
			Object[4].ZPos = Object[ArrayPos0].YPos

			ResetObjectEntity(ArrayPos0, TypeName[Blank Object], 0, 0, 0)
		
		end if
		
		ArrayPos0++
	loop

end event


// ========================
// Editor events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("3D_Test/Objects.gif")
	SpriteFrame(0, 0, 24, 16, 206, 58)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
